// Copyright  2012 Petr TALLA. [petr.talla@gmail.com]
//
// This file is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;  without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// [http://www.gnu.org/copyleft/lesser.html]
//=============================================================================
#include "./TcObject.h"
#include "./TcObjectRegistry.h"
#include <stddef.h>
#include <assert.h>

using namespace std;

//=============================================================================
TcObject::TcObject() :
    id_(++TcObjectRegistry::registry().maxid_),
    status_(OS_NEW)

{   TcObjectRegistry& registry = TcObjectRegistry::registry();

    registry.objects_.insert(pair<int, TcObject*>(id_,this));
    registry.outdated_.push_back(this);
}

//=============================================================================
TcObject::~TcObject()
{   assert(status_ == OS_UPTODATE);
    TcObjectRegistry::registry().objects_.erase(id_);
}

//=============================================================================
void TcObject::changed_()
{   if ( status_ != OS_UPTODATE ) return;
    TcObjectRegistry::registry().outdated_.push_back(this);
    status_ = OS_CHANGED;
}

//=============================================================================
void TcObject::nameSet(const char* name)
{   TcObjectRegistry& registry = TcObjectRegistry::registry();
    registry.named_.insert(pair<string, TcObject*>(string(name),this));
}

//=============================================================================
